package com.youyi.yychosesdk.ui.adapter;

import android.content.Context;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lkx.liandianqinew.R;
import com.youyi.yychosesdk.models.album.entity.AlbumItem;
import com.youyi.yychosesdk.setting.Setting;
import java.util.ArrayList;

public class AlbumItemsAdapter extends RecyclerView.Adapter {
    private static final int TYPE_ALBUM_ITEMS = 1;
    private int adPosition = 0;
    private ArrayList<Object> dataList;
    private OnClickListener listener;
    private LayoutInflater mInflater;
    private int padding = 0;
    private int selectedPosition;

    public interface OnClickListener {
        void onAlbumItemClick(int i, int i2);
    }

    public AlbumItemsAdapter(Context context, ArrayList<Object> arrayList, int i, OnClickListener onClickListener) {
        this.dataList = arrayList;
        this.mInflater = LayoutInflater.from(context);
        this.listener = onClickListener;
        this.selectedPosition = i;
    }

    @Override // android.support.v7.widget.RecyclerView.Adapter
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        return new AlbumItemsViewHolder(this.mInflater.inflate(R.layout.item_dialog_album_items_easy_photos, viewGroup, false));
    }

    @Override // android.support.v7.widget.RecyclerView.Adapter
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int i) {
        if (viewHolder instanceof AlbumItemsViewHolder) {
            if (this.padding == 0) {
                this.padding = ((AlbumItemsViewHolder) viewHolder).mRoot.getPaddingLeft();
            }
            if (i == getItemCount() - 1) {
                ConstraintLayout constraintLayout = ((AlbumItemsViewHolder) viewHolder).mRoot;
                int i2 = this.padding;
                constraintLayout.setPadding(i2, i2, i2, i2);
            } else {
                ConstraintLayout constraintLayout2 = ((AlbumItemsViewHolder) viewHolder).mRoot;
                int i3 = this.padding;
                constraintLayout2.setPadding(i3, i3, i3, 0);
            }
            AlbumItem albumItem = (AlbumItem) this.dataList.get(i);
            AlbumItemsViewHolder albumItemsViewHolder = (AlbumItemsViewHolder) viewHolder;
            Setting.imageEngine.loadPhoto(albumItemsViewHolder.ivAlbumCover.getContext(), albumItem.coverImageUri, albumItemsViewHolder.ivAlbumCover);
            albumItemsViewHolder.tvAlbumName.setText(albumItem.name);
            albumItemsViewHolder.tvAlbumPhotosCount.setText(String.valueOf(albumItem.photos.size()));
            if (this.selectedPosition == i) {
                albumItemsViewHolder.ivSelected.setVisibility(View.VISIBLE);
            } else {
                albumItemsViewHolder.ivSelected.setVisibility(View.INVISIBLE);
            }
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                /* class com.youyi.yychosesdk.ui.adapter.AlbumItemsAdapter.AnonymousClass1 */

                public void onClick(View view) {
                    int i2 = AlbumItemsAdapter.this.selectedPosition;
                    AlbumItemsAdapter.this.selectedPosition = i;
                    AlbumItemsAdapter.this.notifyItemChanged(i2);
                    AlbumItemsAdapter.this.notifyItemChanged(i);
                    AlbumItemsAdapter.this.listener.onAlbumItemClick(i, i);
                }
            });
        }
    }

    public void setSelectedPosition(int i) {
        int i2 = this.selectedPosition;
        this.selectedPosition = i;
        notifyItemChanged(i2);
        notifyItemChanged(i);
        this.listener.onAlbumItemClick(i, i);
    }

    @Override // android.support.v7.widget.RecyclerView.Adapter
    public int getItemCount() {
        return this.dataList.size();
    }

    @Override // android.support.v7.widget.RecyclerView.Adapter
    public int getItemViewType(int i) {
        this.dataList.get(i);
        return 1;
    }

    public class AlbumItemsViewHolder extends RecyclerView.ViewHolder {
        ImageView ivAlbumCover;
        ImageView ivSelected;
        ConstraintLayout mRoot;
        TextView tvAlbumName;
        TextView tvAlbumPhotosCount;

        AlbumItemsViewHolder(View view) {
            super(view);
            this.ivAlbumCover = (ImageView) view.findViewById(R.id.iv_album_cover);
            this.tvAlbumName = (TextView) view.findViewById(R.id.tv_album_name);
            this.tvAlbumPhotosCount = (TextView) view.findViewById(R.id.tv_album_photos_count);
            this.ivSelected = (ImageView) view.findViewById(R.id.iv_selected);
            this.mRoot = (ConstraintLayout) view.findViewById(R.id.m_root_view);
        }
    }
}
